<?php
/**
 * Created by PhpStorm.
 * User: 郝飞
 * Date: 2017/3/17
 * Time: 9:52
 */
namespace Payment\Controller;
use Common\Controller\AdminbaseController;

class AdminHistoryController extends AdminbaseController{

	protected $user_level_model;
	protected $payment_history_model;
	protected $user_model;

	function _initialize() {
		parent::_initialize();
		$this->user_level_model = D('UserLevel');
		$this->payment_history_model = D('PaymentHistory');
		$this->user_model = D('Common/Users');
	}
	/*交易记录*/
	function index(){
		/*查询条件*/
		$class = I("request.trem");

		if(!empty($class)){
			$where['a.classification_id'] = array('eq',$class);
		}
		$start_time=I('request.start_time');
		if(!empty($start_time)){
			$where['a.addtime']=array(
				array('EGT',strtotime($start_time))
			);
		}
		$end_time=I('request.end_time');
		if(!empty($end_time)){
			if(empty($where['addtime'])){
				$where['a.addtime']=array();
			}
			array_push($where['a.addtime'], array('ELT',strtotime($end_time)));
		}
		$keyword=I('request.keyword');
		if(!empty($keyword)){
			$where['c.user_nicename|c.mobile|a.order_number']=array('like',"%$keyword%");
		}
		/*分页*/
		$count =  $this->payment_history_model
			->alias('a')
			->join('__USER_LEVEL__ as b ON a.classification_id = b.classification_id')
			->join('__USERS__ as c ON a.uid = c.id')
			->where($where)
			->count();

		$page = $this->page($count, 100);
		/*获取记录信息*/
		$history_list = $this->payment_history_model
			->alias('a')
			->join('__USER_LEVEL__  as b ON a.classification_id = b.classification_id')
			->join('__USERS__ as c ON a.uid = c.id')
			->where($where)
			->limit($page->firstRow , $page->listRows)
			->field('a.*,b.name,c.user_nicename,c.mobile')
			->order("a.addtime asc")
			->select();
		/*分类信息*/
		$classification_list = $this->user_level_model->select();

		$this->assign("formget",array_merge($_GET,$_POST));
		$this->assign("page", $page->show('Admin'));
		$this->assign('class',$classification_list);
		$this->assign('posts',$history_list);
		$this->display();
	}
}